#include <iostream>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main()
{
	string str;
	queue<int> q1, q2;
	while (cin >> str) {
		if (str == "push") {
			int cur; cin >> cur;
			q1.push(cur);
			while (q2.size()) {
				q1.push(q2.front());
				q2.pop();
			}
			while (q1.size()) {
				q2.push(q1.front());
				q1.pop();
			}
		}
		else if (str == "top") {
			cout << q2.front() << endl;
		}
		else if (str == "pop") {
			cout << q2.front() << endl;
			q2.pop();
		}
		else if (str == "empty") {
			if (q2.empty()) cout << "true" << endl;
			else cout << "false" << endl;
		}
	}
	return 0;
}